<?php
class read_xml {
	private $xml;
	private $json;
	function __construct($file) {
		$this->xml=simplexml_load_file("$file");
		$this->json=array();
		foreach ($this->xml as $key=>$value){
			$this->json["$key"]="$value";
			if($key=="pp"){
				$p=array();
				foreach ($value as $value_p){
					array_push($p,"$value_p");
				}
				$this->json["$key"]=$p;
			}
		}
	}
	function getxml(){
		return json_encode($this->json);
	}
}
class read_xpath{
	private $xml;
	private $info_json,$set_json;
	function __construct($file,$id){
		$this->info_json=array();
		$this->set_json=array();
		$this->xml=new DOMDocument();
		$this->xml->load("$file");
		$xpath=new DOMXPath($this->xml);
		$node=$xpath->query("love[@id='$id']")->item(0);
		$child=$node->childNodes;
		foreach ($child as $value){
			if($value->nodeName=="pp"){
				$arr=array();
				$p_child=$value->childNodes;
				foreach ($p_child as $i){
					array_push($arr,$i->nodeValue);
				}
				$this->info_json["$value->nodeName"]=$arr;
			}else if($value->nodeName=="set"){
				$arr=array();
				$music_child=$value->childNodes;
				foreach ($music_child as $i){
					$arr["$i->nodeName"]=$i->nodeValue;
				}
				$this->set_json["$value->nodeName"]=$arr;
			}else{
				$this->info_json["$value->nodeName"]=$value->nodeValue;
			}
		}
	}
	function get_set_json(){
		return json_encode($this->set_json);
	}
	function get_info_json(){
		return json_encode($this->info_json);
	}
	function get_json(){
		$arr=array();
		$arr["info"]=$this->info_json;
		$arr["set"]=$this->set_json;
		return json_encode($arr);
	}
}
?>